package uk.ac.glasgow.demosocs.tests;

import static org.junit.Assert.*;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.VotingSystemStub;

public class AcceptNominations {
	
	private VotingSystem testVS;

	@Before
	public void setUp() throws Exception {
		testVS = new VotingSystemStub();

		testVS.setCurrentUser("admin", "p");
		testVS.createElection("election", "Simple_Plurality");
		testVS.editElection(new Date(), new Date(), new Date(), "Level_3");
	}

	@After
	public void tearDown() throws Exception {
		testVS = null;
	}

	@Test
	/** 
	 * accepting nomination adds to candidate list
	 */
	public void validAcceptNomination() {

		String ID = testVS.getCurrentElection().getEID();		
		
		Date startD = new Date();
		startD.setTime(startD.getTime() + 1000000000000000000L);
		testVS.editElection(new Date(), startD, startD, "Level_3");

		testVS.setCurrentElection(ID);
		
		testVS.nominateCandidate("2");

		testVS.setCurrentUser("2", "p");
		int sfirst = testVS.getCurrentElection().getCandidates().size();
		testVS.acceptNomination();
	
		int s = testVS.getCurrentElection().getCandidates().size();		

		assertEquals(1, s-sfirst);
	}
	
	@Test
	/** 
	 * accepting nomination of not nominated user doesn't add to candidate list
	 */
	public void invalidAcceptNomination() {

		String ID = testVS.getCurrentElection().getEID();

		Date startD = new Date();
		startD.setTime(startD.getTime() + 1000000000000000000L);
		testVS.editElection(new Date(), startD, startD, "Level_3");

		testVS.setCurrentElection(ID);
		
		testVS.nominateCandidate("2");

		testVS.setCurrentUser("1", "p");
		int sfirst = testVS.getCurrentElection().getCandidates().size();
		testVS.acceptNomination();
	
		int s = testVS.getCurrentElection().getCandidates().size();
		
		
		assertEquals(0, s-sfirst);
	}
	
}